package com.shierke.Ume.ui.adapter.explore

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import com.shierke.Ume.R
import com.shierke.Ume.ui.activity.explore.ExploreDetailsActivity
import com.shierke.Ume.ui.activity.explore.ExploreInvitationDiscussActivity
import com.shierke.Ume.ui.activity.explore.ExploreReportActivity
import com.shierke.Ume.ui.activity.explore.ExploreUserPrincipalActivity
import com.shierke.Ume.util.click
import kotlinx.android.synthetic.main.item_replore_follow.view.*

/**
 * Create by Ybx
 * on 2020-10-14
 * Desribe:
 */
class ExploreFollowAdapter : RecyclerView.Adapter<ExploreFollowAdapter.ViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {

        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_replore_follow, null, false)
        return ViewHolder(view)
    }

    override fun getItemCount() = 10
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.onbind(position)
    }


    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        fun onbind(position: Int) {

            with(itemView) {


                if (position % 2 == 1) {
                    image.setBackgroundResource(R.mipmap.replore3)
                }


                if (position % 2 == 0) {
                    image.setBackgroundResource(R.mipmap.replore1)
                }


                if (position % 3 == 0) {
                    image.setBackgroundResource(R.mipmap.replore2)
                }

                rootView.click {
                    // ExploreInvitationDiscussActivity.startActivity(context)
                    ExploreDetailsActivity.startActivity(context)
                }


                likeImage.click { ExploreReportActivity.startActivity(context) }



                headImage.click {
                    ExploreUserPrincipalActivity.startActivity(context)
                }


                Glide.with(this)
                    .load(R.mipmap.search_result_head)
                    .apply(RequestOptions.bitmapTransform(CircleCrop()))
                    .into(headImage)

            }


        }

    }
}